package com.lp.chapter001.enums;

import lombok.Getter;

/**
 * 性别枚举类
 * @author LP to 2024/03/30
 */
@Getter
public enum SexEnum {

    MAN("0", "男"),
    WOMAN("1", "女"),
    UNKNOWN("2", "未知"),
    ;

    /**
     * 根据name解析成对应枚举value
     */
    public static String resolveToValue(String name) {
        for (SexEnum s : values()) {
            if (s.name.equals(name)) {
                return s.value;
            }
        }
        return UNKNOWN.value;
    }

    /**
     * 根据value解析成对应枚举name
     */
    public static String resolveToName(String value) {
        for (SexEnum s : values()) {
            if (s.value.equals(value)) {
                return s.name;
            }
        }
        return UNKNOWN.name;
    }

    private final String value;
    private final String name;

    SexEnum(String value, String name) {
        this.value = value;
        this.name = name;
    }

}
